package com.leyou.role.controller;

import com.leyou.common.vo.PageResult;
import com.leyou.role.pojo.Role;
import com.leyou.role.service.RoleService;
import org.omg.CORBA.PUBLIC_MEMBER;
import org.springframework.beans.factory.ListableBeanFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class RoleController {

    @Autowired
    private RoleService roleService;


    @GetMapping("/page")
    public ResponseEntity<PageResult<Role>> brandPageQuery(@RequestParam(value = "key", required = false) String key,
                                                               @RequestParam(value = "page", defaultValue = "1") Integer page,
                                                               @RequestParam(value = "rows", defaultValue = "5") Integer rows,
                                                               @RequestParam(value = "sortBy", required = false) String sortBy,
                                                               @RequestParam(value = "desc", required = false) Boolean desc){
        PageResult<Role> pageResult = roleService.rolePageQuery(key, page, rows, sortBy, desc);
        return ResponseEntity.ok(pageResult);
    }

    @GetMapping("/queryByPermission")
    public ResponseEntity<List<Role>> queryByPermission(){
       List<Role> roles=roleService.queryByPermission();
       return ResponseEntity.ok(roles);
    }

    @GetMapping("/queryById")
    public ResponseEntity<Role> queryById(Long id){
       Role role=roleService.queryById(id);
       return ResponseEntity.ok(role);
    }


}
